package com.github.zy.rpc.config;

import com.github.zy.rpc.client.ClientHandler;
import com.github.zy.rpc.client.RpcClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;

/**
 * @version 1.0 created by zy on 2020/4/24 11:11
 */
@Slf4j
public class RpcClientRunner implements CommandLineRunner {

    private final ClientHandler clientHandler;
    private final RpcClient client;

    public RpcClientRunner(ClientHandler clientHandler, RpcClient client) {
        this.clientHandler = clientHandler;
        this.client = client;
    }

    public void start() {
        client.startClient(clientHandler);
    }


    @Override
    public void run(String... args) throws Exception {
        new Thread(this::start).start();
    }
}
